package com.guli.mall.pms.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guli.common.utils.PageUtils;
import com.guli.common.utils.Query;

import com.guli.mall.pms.mapper.CategoryBrandRelationMapper;
import com.guli.mall.pms.entity.CategoryBrandRelationEntity;
import com.guli.mall.pms.service.CategoryBrandRelationService;


@Service("categoryBrandRelationService")
public class CategoryBrandRelationServiceImpl extends ServiceImpl<CategoryBrandRelationMapper, CategoryBrandRelationEntity> implements CategoryBrandRelationService {

    @Override
    public PageUtils queryPage(Integer currentPage,Integer size) {

        Page<CategoryBrandRelationEntity> page = new Page<>(currentPage,size);

        Page<CategoryBrandRelationEntity> resultPage = this.page(page);


        return new PageUtils<>(resultPage);
    }

    @Override
    public PageUtils<CategoryBrandRelationEntity> getCategoryBrandRelationByBrandId(Long brandId, Integer currentPage, Integer size) {

        Page<CategoryBrandRelationEntity> p = new Page<>(currentPage,size);

        QueryWrapper<CategoryBrandRelationEntity> wrapper = new QueryWrapper<>();

        wrapper.eq("brand_id",brandId);

        Page<CategoryBrandRelationEntity> page = this.page(p, wrapper);

        return new PageUtils<>(page);
    }

    @Override
    public void updateCategoryName(Long catelogId, String categoryName) {

        QueryWrapper<CategoryBrandRelationEntity> wrapper = new QueryWrapper<>();

        wrapper.eq("catelog_id",catelogId);

        CategoryBrandRelationEntity categoryBrandRelationEntity = new CategoryBrandRelationEntity();

        categoryBrandRelationEntity.setCatelogName(categoryName);

        this.update(categoryBrandRelationEntity,wrapper);

    }

    @Override
    public List<CategoryBrandRelationEntity> getCategoryBrandRelationListByCategoryId(Long categoryId) {

        QueryWrapper<CategoryBrandRelationEntity> wrapper = new QueryWrapper<>();

        wrapper.eq("catelog_id",categoryId);

        return this.list(wrapper);
    }

}